package com.goldenautumn.prefabricate.activity.mine.order

import android.view.Gravity
import android.view.View
import android.view.Window
import android.view.WindowManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.goldenautumn.prefabricate.R
import com.goldenautumn.prefabricate.activity.mine.adapter.ApplyRefundAdapter
import com.goldenautumn.prefabricate.business.entity.ApplyRefundType
import com.goldenautumn.prefabricate.databinding.DialogApplyRefundBinding
import qncx.external.common.widget.dialog.BaseDialog

class ApplyRefundDialog constructor(val block: (ApplyRefundType) -> Unit) : BaseDialog<DialogApplyRefundBinding>(qncx.external.common.R.style.BottomDialogs) {
    override val layoutRes: Int
        get() = R.layout.dialog_apply_refund

    private val mAdapter by lazy {
        ApplyRefundAdapter()
    }

    override fun onStart() {
        super.onStart()
        val window: Window? = dialog?.window
        val params: WindowManager.LayoutParams? = window?.attributes
        params?.dimAmount = dimAmount
        params?.width = WindowManager.LayoutParams.MATCH_PARENT
        if (height > 0) params?.height = height
        else params?.height = WindowManager.LayoutParams.WRAP_CONTENT
        params?.gravity = Gravity.BOTTOM
        window?.attributes = params
    }

    override suspend fun bindView(view: View): View {
        mBinding.closeBtn.setOnClickListener { dismiss() }

        mBinding.recyclerRv.layoutManager = LinearLayoutManager(context)
        mBinding.recyclerRv.adapter = mAdapter
        mAdapter.submitList(arrayListOf(ApplyRefundType(10,getString(R.string.returns_refunds)),ApplyRefundType(20,getString(R.string.replacement))))

        mAdapter.setOnItemClickListener{_,_,postion ->
            mAdapter.selectPosition = postion
            mAdapter.notifyDataSetChanged()
        }

        mBinding.subBtn.setOnClickListener {
            if(mAdapter.selectPosition != -1){
                mAdapter.getItem(mAdapter.selectPosition)?.let { it1 -> block(it1) }
                dismiss()
            }
        }


        return view
    }
}